package net.sudot.chess.business.controller.admin;

import net.sudot.chess.business.controller.AbstractBaseController;
import net.sudot.chess.business.model.Admin;
import net.sudot.chess.business.service.AdminService;
import net.sudot.commons.security.LoginUser;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户
 *
 * @author tangjialin on 2018-03-22.
 */
@RestController
@RequestMapping(value = "/admin/users")
public class UserController extends AbstractBaseController {

    @Resource
    private AdminService adminService;

    /**
     * 获取登录用户的用户信息
     *
     * @param user 登录用户
     * @return 返回登录用户信息
     */
    @GetMapping("/current")
    public ResponseEntity<Object> current(@LoginUser Admin user) {
        Map<String, Object> data = new HashMap<>();
        data.put("user", user);
        data.put("permissions", adminService.getPermissions(user));
        return ResponseEntity.ok(data);
    }
}
